#ifndef __PROTO_H
#define __PROTO_H

#include <stdarg.h>
#include <stdint.h>


/**
 * 0xE1 0x1E len type seq ... sum 0xEF
 */

#define HEAD0 0xE1
#define HEAD1 0x1E
#define END 0xEF

#define TYPE_NOTIFY 0
#define TYPE_SIMPLE_REQ 1
#define TYPE_SIMPLE_RES 2
#define TYPE_REQ 3
#define TYPE_RES 4
#define TYPE_PING 5
#define TYPE_PONG 6

#define STATUS_LOG 0
#define CMD_MOTOR_CTRL 1
#define CMD_NUM_LED_CTRL 2
#define CMD_DEBUG_IO 3

#define EC_OK 0
#define EC_INVALID 1
#define EC_PARSE 2
#define EC_FAIL 3

uint8_t proto_xor_sum(const uint8_t *buf, uint16_t len);

uint16_t proto_make_printf(uint8_t *buf, const char *fmt, va_list ap);

uint16_t proto_make_simple_res(uint8_t *buf, uint8_t seq, uint8_t cmd,
                               uint8_t ec);

#endif
